package com.maxsalad;

import com.maxsalad.baidu.entity.dish.list.ResponseDishListEntity;
import com.maxsalad.baidu.entity.sku.list.ResponseSkuListEntity;
import com.maxsalad.baidu.service.DishService;
import com.maxsalad.baidu.service.SkuService;
import com.maxsalad.common.util.DateUtil;
import com.maxsalad.common.util.JsonUtil;
import com.maxsalad.eleme.entity.order.detail.ResponseOrderDetailEntity;
import com.maxsalad.eleme.entity.order.list.ResponseOrderListEntity;
import com.maxsalad.pospal.PayMethod;
import com.maxsalad.pospal.entity.order.add.ProductEntity;
import com.maxsalad.pospal.entity.order.add.RequestOrderEntity;
import com.maxsalad.pospal.entity.order.add.ResponseOrder;
import com.maxsalad.pospal.service.OrderService;
import com.maxsalad.uc.em.Platform;
import com.maxsalad.uc.entity.ApiParameterEntity;
import com.maxsalad.uc.entity.ApiParameterUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 2014-400 on 2016-01-27.
 */
public class Main {
    public static void main(String[] args) {
        try {
//            String value = PropertiesUtil.getValue("BAIDU_SOURCE");
//            System.out.println("value=" + value);

//            String data = OkHttpUtil.get("http://121.40.161.96");
//            System.out.println(data);
            test();
            //baiduQueryDish();
            //baiduQuerySku();
            //baiduQueryOrder();
            //postPalAddOrder();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void baiduQueryDish() throws Exception {
        DishService dishService = new DishService();
        ResponseDishListEntity response = dishService.getDishAll("123456");
        System.out.println(JsonUtil.serialize(response));
    }

    private static void baiduQuerySku() throws Exception {
        SkuService skuService = new SkuService();
        ResponseSkuListEntity response = skuService.getSkuList("12344");
        System.out.println(JsonUtil.serialize(response));
    }

    private static void baiduQueryOrder() throws Exception {
        String dd = "2016-03-10 00:00:01";
        com.maxsalad.baidu.service.OrderService orderService = new com.maxsalad.baidu.service.OrderService();
        System.out.println(orderService.getOrderList(DateUtil.strToDateTimeLong(dd, DateUtil.YYYYMMDDHMS) / 1000L, System.currentTimeMillis() / 1000L, "5", 1));
    }


    private static void elemeQueryOrder() throws Exception {
        com.maxsalad.eleme.service.OrderService orderService = new com.maxsalad.eleme.service.OrderService();
        ResponseOrderListEntity listEntity = orderService.getNewOrder();
        String jsonList = JsonUtil.serialize(listEntity);
        System.out.println(jsonList);

        ResponseOrderDetailEntity detailEntity = orderService.getOrderDetail(1);
        String jsonDetail = JsonUtil.serialize(listEntity);
        System.out.println(jsonDetail);
    }

    private static void postPalAddOrder() throws Exception {
        RequestOrderEntity entity = new RequestOrderEntity();
        entity.setContactAddress("上海市长宁区娄山关路523号金虹桥I座706");
        entity.setContactName("张三");
        entity.setContactTel("18616548057");
        entity.setOrderDateTime(DateUtil.getNowDateTime());
        entity.setPayMethod(PayMethod.Cash.toString());
        entity.setShippingFee(BigDecimal.valueOf(2));
        entity.setOrderRemark("订单备注");

        List<ProductEntity> items = new ArrayList<ProductEntity>();
        ProductEntity productEntity = new ProductEntity();
        productEntity.setProductUid(123456);
        productEntity.setQuantity(BigDecimal.valueOf(1));
        productEntity.setManualSellPrice(BigDecimal.valueOf(30));
        productEntity.setComment("打开即食");

        items.add(productEntity);
        entity.setItems(items);

        OrderService orderService = new OrderService();
        ResponseOrder response = orderService.add(1, entity);
        String json = JsonUtil.serialize(orderService);
        System.out.println(json);
    }

    private static void test() {
        List<Integer> data = new ArrayList<Integer>();
        for (int i = 1; i <= 100; i++) {
            data.add(i);
        }

//        List<Integer> rtn = data.stream().filter(t -> t > 2).collect(
//                () -> new ArrayList<Integer>(),
//                (list, item) -> {
//                    if (false == list.contains(item)) {
//                        list.add(item);
//                    }
//                },
//                (list1, list2) -> {
//                    for (Integer item : list2) {
//                        if (false == list1.contains(item)) {
//                            list1.add(item);
//                        }
//                    }
//                });

        List<Integer> rtn = data.stream().filter(t -> t > 2).collect(
                () -> new ArrayList<Integer>(),
                (list, item) -> list.add(item),
                (list1, list2) -> list1.addAll(list2)
        );


        for (Integer item : rtn) {
            System.out.println(item);
        }

    }
}
